import axios from 'axios'
import appconst from './const'
import Vue from 'vue'
import Utils from './Utils'
const ajax = axios.create({
  baseURL: appconst.remoteServiceBaseUrl,
  timeout: 30000
});
ajax.interceptors.request.use(function (config) {
  if (Utils.getToken()) {
    config.headers.common["Authorization"] = "Bearer " + Utils.getToken();
  }
  config.headers.common[".AspNetCore.Culture"] = Utils.getCultureName();
  config.headers.common["Abp.TenantId"] = Utils.getTenantIdCookie();
  return config;
}, function (error) {

  return Promise.reject(error);
});

ajax.interceptors.response.use((respon) => {
  return Promise.resolve(respon)
}, (error) => {
  /*const vm = new Vue({});
  vm.$store.state.error = error;
    if (!!error.response && !!error.response.data.error && !!error.response.data.error.message && error.response.data.error.details) {
     vm.$Modal.error({ title: error.response.data.error.message, content: error.response.data.error.details })
   } else if (!!error.response && !!error.response.data.error && !!error.response.data.error.message) {
     vm.$Modal.error({ title: window.abp.localization.localize("LoginFailed"), content: error.response.data.error.message })
   } else if (!error.response) {
     vm.$Modal.error(window.abp.localization.localize('UnknownError'));
   }
   setTimeout(() => {
     vm.$Message.destroy();
   }, 1000); */

  return Promise.reject(error.response.data);
})
export default ajax;